package com.example.supplychainbackend.entity.sales;

import com.example.supplychainbackend.tool.DateTimeUtils;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.atomic.AtomicInteger;

@Entity
@Table(name = "customer")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class CustomerEntity {
    @Id
    String id;

    String customerCode;
    String uniformCreditCode;
    String customerShortName;
    String customerName;
    String customerLocation;
    Integer customerCategory;
    Integer industryType;
    String businessScope;
    String contactPerson;
    String contactPhone;
    String mobile;
    String fax;
    String email;
    String settlementCurrency;
    String country;
    Integer paymentMethod;
    String province;
    String city;
    String area;
    String pricingProcess;
    String detailAddress;
    String salesPerson;
    Integer amountCalculationBase;
    Integer company;

    @Transient
    private static final AtomicInteger counter = new AtomicInteger(1);

    @PrePersist
    public void generateId() {
        if (id == null || id.equals("")) {
            id = String.format("%s%s%03d",
                    "C", DateTimeUtils.getCurrentDateForID(), counter.getAndIncrement());
            if (customerCode == null || customerCode.equals(""))
                customerCode = id;
        }
    }

}
